package com.viamo.concilia.negocio;

import org.w3c.dom.Document;
import org.w3c.dom.Element;

import com.viamo.concilia.utils.Crypton;

public class Parametro {
    
    private String paramType;
    private String paramName;
    private String paramDescription;
    private String paramValue;
    private boolean paramCrypted;
    
    private static final String TAG_PARAMETER = "PARAMETER";
    private static final String TAG_TYPE = "TYPE";
    private static final String TAG_NAME = "NAME";
    private static final String TAG_VALUE = "VALUE";
    private static final String TAG_CRYPTED = "CRYPTED";
    
    public Parametro(){
            this.paramType="";
            this.paramName="";
            this.paramDescription="";
            this.paramValue="";
            this.paramCrypted=false;
    }
    
    public Parametro(String paramType, String paramName, String paramDescription, String paramValue, boolean paramCrypted)
    {
            this.paramType=paramType;
            this.paramName=paramName;
            this.paramDescription=paramDescription;
            this.paramValue=paramValue;
            this.paramCrypted=paramCrypted;
    }
    
    public Parametro(String paramType, String paramName, String paramValue)
    {
            this.paramType=paramType;
            this.paramName=paramName;
            this.paramValue=paramValue;
            this.paramCrypted=false;
            this.paramDescription="";
    }
    
    public String getParamType() {
            return paramType;
    }
    public void setParamType(String paramType) {
            this.paramType = paramType;
    }
    public String getParamName() {
            return paramName;
    }
    public boolean getParamCrypted() {
            return paramCrypted;
    }
    public void setParamName(String paramName) {
            this.paramName = paramName;
    }
    public String getParamDescription() {
            return paramDescription;
    }
    public void setParamDescription(String paramDescription) {
            this.paramDescription = paramDescription;
    }
    public String getParamValue() {
            return paramValue;
    }
    public void setParamValue(String paramValue) {
            this.paramValue = paramValue;
    }
    public void setParamCrypted(boolean paramCrypted) {
            this.paramCrypted=paramCrypted;
    }
    
    
    public Element toXml(Document xmlDoc){
            
                    Element parameterXML = xmlDoc.createElement(TAG_PARAMETER);
                    
                    //Tipo
                    if(this.getParamType()!= null && this.getParamType().length()>0)
                    {
                            parameterXML.setAttribute(TAG_TYPE, this.getParamType());
                    }
    
                    //Nombre
                    if(this.getParamName() != null )
                    {
                            parameterXML.setAttribute(TAG_NAME, this.getParamName());
                    }
                                                    
                    //Descripcion
                    if(this.getParamDescription() != null)
                    {
                            parameterXML.setTextContent(this.getParamDescription());
                    }
                    
                    //Crypted
                    if(this.getParamCrypted())
                    {
                            //Valor
                            if(this.getParamValue() != null)
                            {
                                    parameterXML.setAttribute(TAG_VALUE, Crypton.encrypt(this.getParamValue()));
                            }
                            parameterXML.setAttribute(TAG_CRYPTED, "YES");
                    }else{
                            //Valor
                            if(this.getParamValue() != null)
                            {
                                    parameterXML.setAttribute(TAG_VALUE, this.getParamValue());
                            }
                            parameterXML.setAttribute(TAG_CRYPTED, "NO");
                    }
                    
                    return parameterXML;

            
    }
    
    
}
